package com.example.demo.easyexcel.dao;

import com.example.demo.easyexcel.db.entity.City;
import com.example.demo.easyexcel.db.repository.CityRepository;
import com.example.demo.easyexcel.util.SelectUtil.ExcelDynamicSelect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CityExcelSelectedImpl implements ExcelDynamicSelect {

    @Autowired
    private CityRepository cityRepository;

    @Override
    public String[] getSource() {
        List<City> aCities = cityRepository.findAll();
        List<String> filtered = aCities.stream().map(City::getName).collect(Collectors.toList());
        String[] strs1 = filtered.toArray(new String[filtered.size()]);
        return strs1;
    }

//  模板
//	@Override
//	public String[] getSource() {
//		CityMapper cityMapper = SpringContextUtil.getBean(CityMapper.class);
//		return cityMapper.selectAllCity().toArray(new String[] {});
//	}

}
